package com.yanqu.road.server.logic.activity.condition.greattrade;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.args.ValueFourParamArgs;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

public class GreatTradeMerchantCondition extends BaseActivityCondition {

    public GreatTradeMerchantCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        ValueFourParamArgs args = (ValueFourParamArgs)object;
        //参数1  不一致时，返回
        if(args.getParams1() != activityConditionInfo.getParamList().get(0).intValue()){
            return;
        }
        //资产百倍
        if(args.getParams1() == 10 && args.getParams3() < activityConditionInfo.getParamList().get(2).intValue()){
            return;
        }
        if(args.getParams1() == 3){
            setValue(getValue().add(args.getValue()));
            return;
        }
        if(args.getValue().compareTo(getValue()) > 0) {
            setValue(new BigInteger(args.getValue().toString()));
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.GreatTradeMerchant.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.GreatTradeMerchant.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        if(getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0){
            return true;
        }
        return false;
    }
}
